;2008-05-20
;Av Benjamin Ingberg och Patrik Johansson
;
;Här ligger alla objectens grundkommandon, som används flitigt för att få schemerman att fungera

(define world-object%
  (class object%
    (init x y w h sprites)
    (super-new)
    
    (define _w w)
    (define _h h)
    (define _x x)
    (define _y y)
    (define _sprites sprites)
    (define _direction 'default)
    (define _counter 0)
    
    (define/public (get-counter)
      _counter)
    (define/public (set-counter value)
      (set! _counter value))
    
    (define/public (set-direction value)
      (set! _direction value))
    (define/public (get-direction)
      _direction)
    
    (define/public (get-x)
      _x)
    (define/public (set-x! value)
      (set! _x value))
    
    (define/public (get-y)
      _y)
    (define/public (set-y! value)
      (set! _y value))
    
    (define/public (get-w)
      _w)
    (define/public (set-w! value)
      (set! _w value))
    
    (define/public (get-h)
      _h)
    (define/public (set-h! value)
      (set! _h value))
    
    (define/public (get-position)
      (list _x _y))
    (define/public (set-position! x y)
      (set! _x x)
      (set! _y y))
    
    (define/public (collides? x y w h)
      (let ((left-a _x)
            (left-b x)
            (right-a (+ _x _w))
            (right-b (+ x w))
            (top-a _y)
            (top-b y)
            (bottom-a (+ _y _h))
            (bottom-b (+ y h)))
        (nor (<= bottom-a top-b)
             (>= top-a bottom-b)
             (<= right-a left-b)
             (>= left-a right-b))))
    
    (define/public (die board)
      (void))
    
    (define/public (get-type)
      'normal)
    
    (define/public (get-sprites)
      _sprites)
    (define/public (set-sprites value)
      (set! _sprites value))
    
    (define/public (draw)
      (send this set-counter (+ (send this get-counter) 1))
      (let ((sprites (send this get-sprites))
            (x (send this get-x))
            (y (send this get-y))
            (w (send this get-w))
            (h (send this get-h))
            (direction (send this get-direction)))
        (let ((sprite (assq direction sprites)))
          (if sprite
              (draw-sprite-bottom-square (cdr sprite) x y w h)
              (let ((sprite (assq 'default sprites)))
                (if sprite
                    (draw-sprite-bottom-square (cdr sprite) x y w h)))))))))